#ifndef TLS_TRIANGLE_H
#define TLS_TRIANGLE_H
#include "geometry.h"

namespace tls{
  struct material;

  struct isect{
    ray r;
    vec3 n;
    vec3 p;
    vec3 tan;
    const material* mat;
    isect():r(vec3(),vec3()){}
  };

  struct triangle{
    geom_tri tri;
    const material* mat;
    triangle(const vec4* a,const vec4* b,const vec4* c,const material* m):
      tri(a,b,c),mat(m){}
    bool intersect(ray& r,isect& hit)const{
      if(tri.intersect(r)){
	hit.r=r;
	hit.n=tri.normal();
	hit.p=r.end();
	hit.tan=(*tri.p1 - *tri.p0).v(); hit.tan.normalize();
	hit.mat=mat;
	return true;
      }
      else return false;
    }
  };


}//namespace tls

#endif
